#
# Creates a docker container with Nexus Artifact Repository
#

FROM ubuntu:20.04

MAINTAINER Marcel Birkner <marcel.birkner@codecentric.de>

ENV SONATYPE_WORK /sonatype-work
ENV NEXUS_VERSION 2.14.1-01
ENV NEXUS_HOME /opt/sonatype/nexus/

# Install Java
RUN apt-get update && \
    apt-get install -y openjdk-8-jdk && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Install packages necessary
RUN apt-get update && \
    apt-get install -y unzip && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Download and extract Nexus
ADD https://download.sonatype.com/nexus/oss/nexus-${NEXUS_VERSION}-bundle.zip /tmp/nexus-${NEXUS_VERSION}-bundle.zip
RUN mkdir -p ${NEXUS_HOME} && \
    unzip /tmp/nexus-${NEXUS_VERSION}-bundle.zip -d /tmp && \
    cp -r /tmp/nexus-${NEXUS_VERSION}/* ${NEXUS_HOME} && \
    rm -rf /tmp/nexus-${NEXUS_VERSION}-bundle.zip /tmp/nexus-${NEXUS_VERSION}

# Create Nexus user and group
RUN groupadd -r nexus -g 3001 && \
    useradd -u 3001 -r -g nexus -m -d ${SONATYPE_WORK} -s /bin/bash -c "Nexus Run User" nexus

VOLUME ${SONATYPE_WORK}

EXPOSE 8081

WORKDIR ${NEXUS_HOME}


ENV CONTEXT_PATH /
ENV MAX_HEAP 768m
ENV MIN_HEAP 256m
ENV JAVA_OPTS -server -XX:MaxPermSize=192m -Djava.net.preferIPv4Stack=true
ENV LAUNCHER_CONF ./conf/jetty.xml ./conf/jetty-requestlog.xml

# Set the command to run Nexus
CMD ["sh", "-c", "java -Dnexus-work=${SONATYPE_WORK} -Dnexus-webapp-context-path=${CONTEXT_PATH} -Xms${MIN_HEAP} -Xmx${MAX_HEAP} -cp 'conf/:lib/*' ${JAVA_OPTS} org.sonatype.nexus.bootstrap.Launcher ${LAUNCHER_CONF}"]
